package utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonUtils {
	public static String getJSONStringFromUrl(String url) throws MalformedURLException, IOException
	{
		InputStream inputStream = new URL(url).openConnection().getInputStream();
		BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
		StringBuilder sb = new StringBuilder();
		String line;
		while ((line = br.readLine()) != null) {
			sb.append(line+"\n");
		}
		br.close();
		inputStream.close();
		return sb.toString();
	}

	public static JSONArray getArray(String url) throws JSONException, MalformedURLException, IOException
	{
		return new JSONArray(getJSONStringFromUrl(url));		
	}
	
	
	
	

}
